package com.example.mytestdemo

import android.content.Intent
import android.os.Bundle
import android.widget.Button
import android.widget.FrameLayout
import androidx.appcompat.app.AppCompatActivity
import com.example.mytestdemo.widget.demo2.LiveLightAnimPresenter
import com.example.mytestdemo.widget.demo3.BubbleView
import com.example.mytestdemo.widget.demo4.BullbeBeautyView
import com.example.mytestdemo.widget.demo4.BullbeData
import com.example.mytestdemo.widget.demo4.OnCommonCallBack

class MainActivity : AppCompatActivity() {


    private val mLayRootMain: FrameLayout by lazy { findViewById<FrameLayout>(R.id.lay_root_main) }
    private val mLayBubble: BubbleView by lazy { findViewById<BubbleView>(R.id.lay_bubble) }
    private val mLayBullbeview: BullbeBeautyView by lazy { findViewById<BullbeBeautyView>(R.id.lay_bullbeview) }
    private val mBtnTest: Button by lazy { findViewById<Button>(R.id.btn_test) }

    private var mLightAnimPresenter: LiveLightAnimPresenter? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        initView();
        initDemo4()
    }

    private fun initDemo4() {


        val strImgUrl1 = "https://www.xrmn5.com/uploadfile/202209/20/1417591942.jpg"
        val strImgUrl2 = "https://www.xrmn5.com/uploadfile/202209/22/F518119646.jpg"
        val strImgUrl3 = "https://www.xrmn5.com/uploadfile/202209/22/7018032253.jpg"
        val strImgUrl4 = "https://www.xrmn5.com/uploadfile/202209/21/5518010640.jpg"
        val strImgUrl5 = "https://www.xrmn5.com/uploadfile/202109/6/C122516988.jpg"
        val listdatas: MutableList<BullbeData> = mutableListOf()
        listdatas.add(BullbeData(strImgUrl1, "1", ""))
        listdatas.add(BullbeData(strImgUrl2, "2", ""))
        listdatas.add(BullbeData(strImgUrl3, "3", ""))
        listdatas.add(BullbeData(strImgUrl4, "4", ""))
        listdatas.add(BullbeData(strImgUrl5, "5", ""))
        mLayBullbeview.listData = listdatas
        mLayBullbeview.onCommonCallBack = object : OnCommonCallBack {
            override fun onAchieve(strId: String, strUrl: String, type: Int) {
                startActivity(Intent(this@MainActivity, InfoActivity::class.java));

            }
        }
    }


    private fun initView() {
        mLightAnimPresenter =
            LiveLightAnimPresenter(
                this,
                mLayRootMain
            )

        mBtnTest.setOnClickListener {
//            mLayBubble.ini
            playLightAnim()
        }

    }

    /**
     * 播放飘心动画
     */
    fun playLightAnim() {
        if (mLightAnimPresenter != null) {
            mLightAnimPresenter!!.play()
        }
    }

    override fun onDestroy() {
        super.onDestroy()
        if (mLightAnimPresenter != null) {
            mLightAnimPresenter!!.release()
        }

    }

    override fun onResume() {
        super.onResume()
        mLayBullbeview.showBubble()
    }

    override fun onPause() {
        super.onPause()
        mLayBullbeview.hideBubble()

    }
}